﻿#ifndef TCPSOCKET_H
#define TCPSOCKET_H

#include <QObject>
#include <QTcpSocket>
#include <QTimer>
#include "common.h"

struct TopicMess{
    QString TopicName;
    bool is_Get;
    int Topic_Time_Interval;
    int m_LastRecvDelay;
};

class TcpSocket: public QObject
{
    Q_OBJECT
public:
    explicit TcpSocket(int type,QObject *parent = 0);
    ~TcpSocket();

signals:

    void sig_RevData(QString type,QStringList data);

    void sig_inConnect(bool isConnect);

    void sig_mapTopicPgm(QPixmap pixmap);

    void sig_Loger(QString logger);


public:
    int m_tcp_Type = 1;
    QList<TopicMess> m_TopicMess;
    QTcpSocket* m_socket = NULL;  //底盘通信
    QString m_Ip;
    int m_Port;
    QTimer *m_Timer = NULL;
    QByteArray m_ByteDataTcp;

    int m_SocketRecvDelay = 0;//TCP超时

public slots:
    void slot_isSubscribe(bool isSub);
    void slotTcpRevData();

    bool connectToHost(QString ip,int port);

    QString on_controlMove(QString key);

    QString on_SendXYZMove(QString data);

    void slot_SocketSendData(QString Type,QString data);
    void sendData(QString Msg);

    void slot_Timer();


    void DataToPgm(QVariantList dataList,int width,int height);
    void displayPGM(int8_t *data, int width, int height, int maxValue);
    void savePGM(const std::string& filename, int8_t* data, int width, int height, int max_value);

};

#endif // TCPSOCKET_H
